#include "fcn.h"
using namespace std;

void HeapSort(vector<int> & ivec)
{
	int theSize = ivec.size();
	for (int i = theSize / 2; i >= 0; --i)
	{
		percolateDown(ivec, i, theSize);
	}

	//cout << "---" << endl;

	for (int j = theSize - 1; j > 0; --j)
	{
		cout << "max = " << ivec[0] << " move to position" << j << endl;
		
		swap(ivec[j], ivec[0]);
		percolateDown(ivec, 0, j);
	}
}

//extremly important!
int leftChild(int pos)
{
	if (pos == 0)
		return 1;
	else
		return 2 * pos;
}

void percolateDown(vector<int> & ivec , int pos , int cursiz)
{
	int temp = ivec[pos];
	int child = 0;
	int hole = pos;
	for (; leftChild(hole) < cursiz; hole = child)
	{
		//cout << "down" << endl;
		child = leftChild(hole);
		if (child + 1 < cursiz && ivec[child + 1] > ivec[child])
			child++;
		if (ivec[child] < temp)
		{
			break;
		}
		else{
			ivec[hole] = ivec[child];
		}
	}
	ivec[hole] = temp;

	//cout << "pdown end" << endl;
}

void InsertionSort(vector<int> & ivec)
{
	int p = 0, temp = 0, i = 0;

	for ( p = 1; p < ivec.size(); ++p)
	{
		temp = ivec[p];
		for (i = p; i > 0 && temp < ivec[i - 1]; --i)
			ivec[i] = ivec[i - 1];
		ivec[i] = temp;
	}
}





int main()
{
	int num;
	vector<int> arr;
	while (cin >> num)
	{
		if (num == 12306)
		{
			InsertionSort(arr);
		}
		else if (num == 12312)
		{
			for (int i = 0; i < arr.size(); ++i)
			{
				cout << arr[i] << " ";
			}
		}
		else{
			arr.push_back(num);
		}


	}


}

